import matplotlib.pyplot as plt
import scipy.io.wavfile as wave
import numpy as np

sampleFreq, snd = wave.read('sound.wav')
timeArray = np.arange(0, snd.shape[0], 1)
timeArray = (timeArray / sampleFreq) * 1000

snd = (snd / 2 + 2 ** 14) / 2 ** 7
snd = snd.astype('uint8')
plt.plot(timeArray, snd)
plt.show()
wave.write('test.wav', sampleFreq, snd)

count = 0
print('const unsigned uint16 waveFreq = %d;\n' % sampleFreq, end='')
print('const unsigned char waveData[%d] = {\n' % snd.shape[0], end='')
for i in snd:
    print('0x%02x,' % i, end='')
    count += 1
    if count % 32 == 0:
        print('\n', end='')
print('\n};')
